<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta http-equiv="X-UA-Compatible"content="IE=8"><!--以IE8模式渲染-->
	<meta http-equiv="X-UA-Compatible"content="IE=7"><!--以IE7模式渲染-->
	<meta http-equiv="X-UA-Compatible"content="IE=9; IE=8; IE=7; IE=EDGE">

	<title>后台角色管理</title>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/manage1.css" >
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/role_add.css" >
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.css"/>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery_validate/css/validationEngine.jquery.css" >
	<script TYPE="text/javascript" src="__PUBLIC__/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.easydrag.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.js"></script>
	<script TYPE="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script TYPE="text/javascript" src="__PUBLIC__/js/ajax.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery_validate/js/jquery.validationEngine.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery_validate/js/jquery.validationEngine-zh_CN.js"></script>
	<style type="text/css">
		.demo {
			width:350px; margin:10px auto auto 0px;height:20px;
		}
		table.gridtable {
			font-family: verdana,arial,sans-serif;
			font-size:11px;
			color:#333333;
			border-width: 1px;
			border-color: #666666;
			border-collapse: collapse;
			margin-top: 10px;
			margin-left: 70px;
		}
		table.gridtable th {
			width: 50px;
			border-width: 1px;
			padding: 8px;
			border-style: solid;
			border-color: #666666;
			background-color: #dedede;
		}
		table.gridtable td {
			width: 100px;
			border-width: 1px;
			padding: 8px;
			border-style: solid;
			border-color: #666666;
			background-color: #ffffff;
		}
	</style>
</head>
<body>
	<form action="../../order/order/order_add" method="post" id="order_add" name="order_add">
		<div style="height:404px;">
			<div style="height:550px;width:500px;border: 1px solid  green;float:left;">
				<input type="hidden" id="custid" name="custid">
				<table class="addForm" >
					<tr>
						<th>客户电话</th>
						<td><input type="text" name="cust_phone" id="cust_phone" onblur="findCustomer(this);"></td>
					</tr>

					<tr>
						<th>客户姓名</th>
						<td><input type="text" id="custname" readonly="readonly"></td>
					</tr>

					<tr>
						<th>服务价格</th>
						<td>
							<input type="text" name="allmoney" id="allmoney" onblur="mathMoney();">（元）
						</td>
					</tr>

					<tr>
						<th>客户首付</th>
						<td>
							<input type="text" name="fac_payment" id="fac_payment" value='0' onblur="mathMoney();">（元）
						</td>
					</tr>

					<tr>
						<th>利率（%）</th>
						<td>
							<input type="text" name="borrow_rate" id="borrow_rate" onblur="mathMoney();">
						</td>
					</tr>

					<tr>
						<th>选择工号</th>
						<td>
							<select name="trade_pernumber" id="trade_pernumber">
								<option value=''>请选择</option>
								<?php 
									foreach ($array_person as $key => $value) 
									{
										echo '<option value="'.$value['facp_workid'].'">'.$value['facp_name'].'</option>';
									}
								?>
							</select>
						</td>
					</tr>

					<tr>
						<td colspan="2" class="addButton">
							<input type="button" value="保存" class="save" onclick="formSubmit();">
							<input type="reset" value="重置" class="clear"></td>
						</td>
					</tr>
				</table>
			</div>

			<div style="height:550px;width:500px;border: 1px solid  green;float:left;">
				<div  style="height:350px;width:500px;border: 1px solid  green;">
					<h3>
						交易编号：<span id="contractnumber"></span><br/><br/>
					</h3>
					<h3>
						交易二维码：
					</h3>
					<img src="" name='tradeimg' id='tradeimg'>
				</div>

				<h3>借款总额参考:</h3>
				<div>
					<table class='gridtable'>
						<tr>
							<th>期数</th>
							<th>每月还款（元）</th>
							<th>期数</th>
							<th>每月还款（元）</th>
						</tr>
						<tr>
							<th>6期</th>
							<td id='six_period'>------</td>
							<th>9期</th>
							<td id='nine_period'>------</td>
						</tr>
						<tr>
							<th>12期</th>
							<td id='twelve_period'>------</td>
							<th>18期</th>
							<td id='eighteen_period'>------</td>
						</tr>
						<tr>
							<th>24期</th>
							<td id='twenty_four'>------</td>
							<th>------</th>
							<td>------</td>
						</tr>
					</table>
				</div>
			</div>
		</div>
	</form>

	<script type="text/javascript">
		function formSubmit() 
		{
			if(phoneValidate() & custValidate() & priceValidate() & fac_paymentValidate() & borrow_rateValidate() & trade_pernumberValidate()) 
			{
				// $("#order_add").submit();
				$(".save").attr("disabled","disabled");
				var url = "../../order/order/order_add";
				var data = $("#order_add").serialize();
				$.ajax({
					type: "post",
					async: true,
					data: data,
					url: url,
					success: function(d) 
					{
						var dataObj = JSON.parse(d);
						var state = dataObj.state;
						if(state == 1) 
						{
							jAlert('新增订单成功！','新增提示',null);
							$("#contractnumber").html(dataObj.trade_contractnumber);
							$("#tradeimg").attr("src","../"+dataObj.trade_orimage);
						}
						else
						{
							jAlert('新增订单失败！','新增提示',null);
						}
					},
					error: function(e) 
					{
						jAlert('网络错误，请稍后重试！','新增提示',null);
					}
				});
			}
		}

		function findCustomer(obj) 
		{
			var url = "../../order/order/findCustomer";
			var value = obj.value;
			var data = {"phone":value};
			$.ajax({
				type: "post",
				async: true,
				data: data,
				url: url,
				success: function(d) 
				{
					var dataObj = JSON.parse(d);
					var state = dataObj.state;
					if(state == 1) 
					{
						$("#custname").val(dataObj.cust_name);
						$("#custid").val(dataObj.cust_id);
					}
					else
					{
						jAlert('未找到该客户！','新增提示',null);
						$("#custname").val('');
						$("#custid").val('');
					}
				},
				error: function(e) 
				{
					jAlert('网络错误，请稍后重试！','新增提示',null);
				}
			});
		}

		//	客户电话验证1
		function phoneValidate() 
		{
			var value = $("#cust_phone").val();
			if(value == null || value == '') 
			{
				jAlert("手机号码不能为空！", '错误提示', null);
				return false;
			}
			else if(value.length != 11)
			{
				jAlert("请输入正确的手机号码！", '错误提示', null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	客户电话验证2
		function custValidate() 
		{
			var value = $("#custid").val();
			if(value == null || value == '') 
			{
				jAlert("请输入正确的手机号码！", '错误提示', null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	服务价格验证
		function priceValidate() 
		{
			var value = $("#allmoney").val();
			var reg = new RegExp("^[0-9]*$");
			if(value == '' || value == null) 
			{
				jAlert("服务价格不能为空！",'错误提示',null);
				return false;
			}
			else if(!reg.test(value)) 
			{
				jAlert("服务价格必须为整数数字！",'错误提示',null);
				return false;
			}
			else if(value > 50000) 
			{
				jAlert("金额不能超过50000元！",'错误提示',null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	客户首付验证
		function fac_paymentValidate() 
		{
			var value = $("#fac_payment").val();
			var allmoney = $("#allmoney").val();
			var reg = new RegExp("^[0-9]*$");
			if(value == '' || value == null) 
			{
				jAlert("客户首付不能为空！",'错误提示',null);
				return false;
			}
			else if(!reg.test(value)) 
			{
				jAlert("客户首付必须为整数数字！",'错误提示',null);
				return false;
			}
			else if(value >= 50000) 
			{
				jAlert("金额不能超过50000元！",'错误提示',null);
				return false;
			}
			else if(value >= allmoney) 
			{
				jAlert("首付金额不能超过服务价格！",'错误提示',null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	利率验证
		function borrow_rateValidate() 
		{
			var value = $("#borrow_rate").val();
			if(value == '' || value == null) 
			{
				jAlert("利率不能为空！",'错误提示',null);
				return false;
			}
			else
			{
				return true;
			}
		}

		//	工号验证
		function trade_pernumberValidate() 
		{
			var value = $("#trade_pernumber").val();
			if(value == '' || value == null) 
			{
				jAlert("工号不能为空！",'错误提示',null);
				return false;
			}
			else
			{
				return true;
			}
		}

		function mathMoney() 
		{
			var allmoney = $("#allmoney").val();
			var fac_payment = $("#fac_payment").val();
			var borrow_rate = $("#borrow_rate").val();

			if (allmoney != '' & fac_payment != '' & borrow_rate != '') 
			{
				var money = allmoney-fac_payment;
				$("#six_period").html(((money*borrow_rate/1200*6+money)/6).toFixed(2));
				$("#nine_period").html(((money*borrow_rate/1200*9+money)/9).toFixed(2));
				$("#twelve_period").html(((money*borrow_rate/1200*12+money)/12).toFixed(2));
				$("#eighteen_period").html(((money*borrow_rate/1200*18+money)/18).toFixed(2));
				$("#twenty_four").html(((money*borrow_rate/1200*24+money)/24).toFixed(2));
			}
		}
	</script>
</body>
</html>